<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<link rel="stylesheet" type="text/css" href="../../extjs_all/resources/css/ext-all.css"></link>
<script type="text/javascript" src="../../extjs_all/adapter/ext/ext-base.js"></script>
<script type="text/javascript" src="../../extjs_all/ext-all.js"></script>
<script type="text/javascript" src="../../extjs_all/source/locale/ext-lang-zh_CN.js"></script>

<script type="text/javascript">

Ext.onReady(function() {
    Ext.QuickTips.init();
    Ext.BLANK_IMAGE_URL = "../../extjs_all/resources/images/default/s.gif";
    var mytree = new Ext.tree.TreePanel({
    		//	renderTo:'tree',
               // el : "container",
                animate : true,
                title : "简单Extjs动态树",
                collapsible : true,
                enableDD : true,
                enableDrag : true,
                rootVisible : true,
                autoScroll : true,
                autoHeight : true,
                width : 150,
              
                lines : true
            });

    // 根节点
    var root = new Ext.tree.TreeNode({
                id : "root",
                text : "根节点",
                expanded :true,
                checked : false
            });
    for (var j = 1; j < 4; ++j) {
        var node = root.appendChild(new Ext.tree.TreeNode({
        			id:'A_'+j,
                    text : '客户企业A' + j,
                    //allowDrag : false,
                    checked : false
                }));
        for (var n = 1; n < 4; ++n) {
            node.appendChild(new Ext.tree.TreeNode({
            			id:'B_'+j+'_'+n,
                        text : '栏目' + n,
                        allowDrag : false,
                        checked : false
                    }));
        }
    }
    mytree.setRootNode(root);
    mytree.render(document.body);
    mytree.on('checkchange', function(node, checked) {
                node.expand();
                node.attributes.checked = checked;
                node.eachChild(function(child) {
                            child.ui.toggleCheck(checked);
                            child.attributes.checked = checked;
                            child.fireEvent('checkchange', child,
                                    checked);
                        });
            }, mytree);
    var button = new Ext.Button({
                text : "选中id",
                handler : function() {
                    var b = mytree.getChecked();
                    var checkid = new Array;// 存放选中id的数组
                    for (var i = 0; i < b.length; i++) {
                        checkid.push(b[i].id);// 添加id到数组
                    }
                    alert(checkid.toString());
                }
            }).render(document.body, "btn");

});

</script>
</head>
<body>
<iframe name="toolbar" id="toolbar" width="550px" height="32px" scrolling='no' frameborder="1" src="http://www.call400.net/toolbar/toolbar.php?type=bs">
    </iframe>
<div id='tree'></div>
</body>
</html>